import * as XLSX from "xlsx";
export function xlsx(headers, data,type,filename = '.xlsx') {//导出xlsx
    // const headers = ['姓名', '年龄', '性别']
    // const data = this.tableData.map(item => [item.name, item.age, item.gender])

    const worksheet = XLSX.utils.aoa_to_sheet([headers, ...data])
    let wscols = [    // 每列不同宽度px
    { wch: 20 }
  ]
    for (let i = 0; i < data[0].length; i++) {  
        wscols.push({ wch: 20 });
  }

  worksheet["!cols"] = wscols;
  let wsrows = [{ hpx: 20 }];  // 
  for (let i = 0; i <= data[0].length; i++) {   // total  列表条数
    wsrows.push({ hpx: 20 });
  }
  worksheet["!rows"] = wsrows;
    const workbook = XLSX.utils.book_new()
    XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
    XLSX.writeFile(workbook, type+'.xlsx')
  }
